var reverse = function(x) {
  let result = 0;
  while(x !== 0) {
      result = result * 10 + x % 10;
      x = (x / 10) | 0;
      console.log(x)
  }
  return (result | 0) === result ? result : 0;
};
console.log(reverse(123))